package com.oig.sys.auth.dao;

import com.oig.sys.auth.entity.TbUserColumn;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
@author wuxl
*/
public interface ITbUserColumnDao extends JpaRepository<TbUserColumn, Integer> {

	TbUserColumn getTbUserColumnById(Integer id);


	@Query("select c.resourceId from TbUserColumn c where c.userId=:userId")
	List<Integer> findAllUCResourceIdByUserId(@Param("userId") Integer userId) ;

	@Query("select c.id from TbUserColumn c where c.resourceId=:resourceId")
	List<Integer> findIdByResourceId(@Param("resourceId") Integer resourceId) ;

	@Query("select c.userId from TbUserColumn c where c.resourceId=:resourceId")
	List<Integer> findUserIdByResourceId(@Param("resourceId") Integer resourceId) ;

	@Query("from TbUserColumn c where c.resourceId=:resourceId")
	List<TbUserColumn> getByResourceId(@Param("resourceId") Integer resourceId) ;

	TbUserColumn getByResourceIdAndUserId(Integer resourceId, Integer userId);

	@Modifying
	@Query("delete from TbUserColumn c where c.id in(:idList)")
	void deleteByIdList(@Param("idList") List<Integer> idList);
}
